package com.example.xpvideo.entity;

import com.example.xpvideo.enums.ErrCodeEnum;

import java.util.ArrayList;

/**
 * The type Response result.
 *
 * @param <T> the type parameter
 * @ClassName: ResponseResult
 * @Description: ResponseResult
 * @Author: zzz
 * @Date: 2020 -04-04 21:52
 */
public class ResponseResult<T> {
    /**
     * 错误码
     */
    private Integer errno;
    /**
     * 错误信息
     */
    private String errmsg;
    /**
     * 数据模板
     */
    private T data;
    /**
     * 数据模板1
     */
    private T data1;

    /**
     * Instantiates a new Response result.
     *
     * @param errCodeEnum the err code enum
     * @param data        the data
     */
    public static <T>ResponseResult<T> responseResult(ErrCodeEnum errCodeEnum,
                                                      T data) {

        ResponseResult<T> entity = new ResponseResult<T>();
        entity.setData(data);
        entity.setErrmsg(errCodeEnum.getMessage());
        entity.setErrno(errCodeEnum.getCode());
        return entity;
    }

    /**
     * Instantiates a new Response result.
     *
     * @param errno  the errno
     * @param errmsg the errmsg
     */
    public static <T>ResponseResult<T> responseResult(Integer errno,
                                                   String errmsg) {

        ResponseResult<T> entity = new ResponseResult<T>();
        entity.setData((T) new ArrayList<>());
        entity.setErrmsg(errmsg);
        entity.setErrno(errno);
        return entity;

    }

    /**
     * Instantiates a new Response result.
     *
     * @param errno the errno
     */
    public static <T>ResponseResult<T> responseResult(Integer errno) {

        ResponseResult<T> entity = new ResponseResult<T>();
        entity.setData((T) new ArrayList<>());
        entity.setErrmsg("");
        entity.setErrno(errno);
        return entity;

    }

    /**
     * Instantiates a new Response result.
     *
     * @param errno  the errno
     * @param errmsg the errmsg
     * @param data   the data
     */
    public static <T>ResponseResult<T> responseResult(Integer errno,
                                                   String errmsg,
                                                   T data) {

        ResponseResult<T> entity = new ResponseResult<T>();
        entity.setData(data);
        entity.setErrmsg(errmsg);
        entity.setErrno(errno);
        return entity;

    }
    public static <T>ResponseResult<T> responseResult(Integer errno,
                                                      String errmsg,
                                                      T data1,
                                                      T data) {

        ResponseResult<T> entity = new ResponseResult<T>();
        entity.setData(data);
        entity.setData1(data1);
        entity.setErrmsg(errmsg);
        entity.setErrno(errno);
        return entity;

    }
    /**
     * Instantiates a new Response result.
     *
     * @param errno the errno
     * @param data  the data
     */
    public static <T>ResponseResult<T> responseResult(Integer errno,
                                                   T data) {
        ResponseResult<T> entity = new ResponseResult<T>();
        entity.setData(data);
        entity.setErrmsg("");
        entity.setErrno(errno);
        return entity;

    }

    /**
     * Gets errno.
     *
     * @return the errno
     */
    public Integer getErrno() {
        return errno;
    }

    /**
     * Sets errno.
     *
     * @param errno the errno
     */
    public void setErrno(Integer errno) {
        this.errno = errno;
    }

    /**
     * Gets errmsg.
     *
     * @return the errmsg
     */
    public String getErrmsg() {
        return errmsg;
    }

    /**
     * Sets errmsg.
     *
     * @param errmsg the errmsg
     */
    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    /**
     * Gets data.
     *
     * @return the data
     */
    public T getData() {
        return data;
    }

    /**
     * Sets data.
     *
     * @param data the data
     */
    public void setData(T data) {
        this.data = data;
    }
    /**
     * Gets data1.
     *
     * @return the data
     */
    public T getData1() {
        return data1;
    }

    /**
     * Sets data1.
     *
     * @param data1 the data1
     */
    public void setData1(T data1) {
        this.data1 = data1;
    }
}
